/**
 * @projectName demo-master
 * @fileName TestController.java
 * @packageName org.example.consumer.controller
 * @author xaoyaoyao
 * @date 2021/3/24 09:45
 * @version V1.0
 * @copyright (c) 2021, xaoyaoyao@aliyun.com All Rights Reserved.
 */
package org.example.consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author xaoyaoyao
 * @className TestController
 * @description
 * @date 2021/3/24 09:45
 */
@RestController
public class TestController {

	private final RestTemplate restTemplate;

	@Autowired
	public TestController(RestTemplate restTemplate) {
		this.restTemplate = restTemplate;
	}

	@RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
	public String echo(@PathVariable String str) {
		return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
	}

	@GetMapping("/consumer")
	public String test() {
		String result = restTemplate.getForObject("http://service-provider/helloNacos", String.class);
		return "Return : " + result;
	}
}
